#include<iostream>
using namespace std;
#include<unistd.h>
#include<pthread.h>
#include<vector>
void* Threadrun(void* args)
{
    string name = static_cast<char*>(args);
    int cnt = 100;
    while (cnt--)
    {
        cout << name << " is run!" << endl;
        sleep(1);
    }
    return args;
}
int main()
{
    vector<pthread_t> tids;
    int num = 3;
    for (int i = 0; i < num; i++)
    {
        pthread_t id;
        char* name=new char[128];
        snprintf(name,128,"thread-%d",i+1);
        pthread_create(&id, nullptr, Threadrun, name);
        tids.emplace_back(id);
    }

    for (auto i : tids)
    {
        pthread_cancel(i);
        void *ret;
        pthread_join(i, &ret);
        cout << (long long)ret  << endl;
        // void *name;
        // pthread_join(i, (void**)&name);
        // cout << name << " over!" << endl;
    
    }
    return 0;
}